package cn.czh0123.controller;

import cn.czh0123.domain.MessageBoard;
import cn.czh0123.query.MessageBoardQuery;
import cn.czh0123.service.IMessageBoardService;
import cn.czh0123.utils.ResultWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 留言板控制层
 */
@RestController
@RequestMapping("messageBoard")
public class MessageBoardController {

    @Resource
    private IMessageBoardService messageBoardService;

    @GetMapping("/list")
    public ResultWrapper<IPage<MessageBoard>> list(MessageBoardQuery qo) {
        return ResultWrapper.success(messageBoardService.queryPage(qo));
    }

    @DeleteMapping("/delete")
    public ResultWrapper<?> delete(Long id) {
        messageBoardService.removeById(id);
        return ResultWrapper.success();
    }

    @PostMapping("/add")
    public ResultWrapper<MessageBoard> add(@Valid @RequestBody MessageBoard messageBoard) {
        return ResultWrapper.success(messageBoardService.saveMessageBoard(messageBoard));
    }
}
